package com.ymatou.iapi.productsync.testcase;

import java.util.Arrays;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellerproduct.service.BatchDeleteProductsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.NewJavaMongoCheckService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.MapUtil;

public class Ts_DeleteProductExecutorConfig {
	private static BatchDeleteProductsCall batchdeleteproductsCall = new BatchDeleteProductsCall();
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");


	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("DeleteProductExecutorConfig测试");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult("DeleteProductExecutorConfig");
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BatchDeleteProducts_001() {
		Logger.start(true,"单规格删除普通商品");
		try {
			//发布一个未立即上架的商品
			String productId1 = SellerProductCallService.addNewProductNotOnSale(sellerId, sellerName, null).getJSONObject("Data").getString("ProductID");
			//批量删除商品
			batchdeleteproductsCall.callAndGetReturnData(MapUtil.hashMap("ProductIds", new JSONArray(Arrays.asList(productId1)), "UserID", sellerId));
			//比对
			NewJavaMongoCheckService.checkProductAsDeleteMgoSyncBySQL_NewJavaMgo(productId1);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BatchDeleteProducts_002() {
		Logger.start(true,"多规格删除普通商品");
		try {
			//TODO 补全case代码

			//发布一个未立即上架的商品
			JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc10.json");	
			JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID", sellerId,"LoginID", sellerName));
			String productId1 = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");
			
			//批量删除商品
			batchdeleteproductsCall.callAndGetReturnData(MapUtil.hashMap("ProductIds", new JSONArray(Arrays.asList(productId1)), "UserID", sellerId));
			
			//比对
			NewJavaMongoCheckService.checkProductAsDeleteMgoSyncBySQL_NewJavaMgo(productId1);	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BatchDeleteProducts_004() {
		Logger.start(true,"删除带运费模板商品");
		try {
			JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc13.json");	
			JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID", sellerId,"LoginID", sellerName));
			String productId1 = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");
			
			//批量删除商品
			batchdeleteproductsCall.callAndGetReturnData(MapUtil.hashMap("ProductIds", new JSONArray(Arrays.asList(productId1)), "UserID", sellerId));
			
			//比对
			NewJavaMongoCheckService.checkProductAsDeleteMgoSyncBySQL_NewJavaMgo(productId1);	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
}
